package com.toprs.business.extend

import org.mybatis.dynamic.sql.BindableColumn
import org.mybatis.dynamic.sql.render.TableAliasCalculator
import org.mybatis.dynamic.sql.select.function.AbstractUniTypeFunction
import java.math.BigDecimal


class MySum(column: BindableColumn<BigDecimal>) : AbstractUniTypeFunction<BigDecimal, MySum>(column) {

    override fun renderWithTableAlias(tableAliasCalculator: TableAliasCalculator?): String {
        val t = column.renderWithTableAndColumnAlias(tableAliasCalculator)
        return "COALESCE(sum(${t}),0)"
    }

    override fun copy(): MySum {
        return MySum(column)
    }

    companion object {
        fun of(column: BindableColumn<BigDecimal>, alias: String? = ""): MySum {

            val col = MySum(column)
            col.alias = alias
            return col
        }
    }


}